#include<bits/stdc++.h>
//#include<ext/pb_ds/hash_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int N=4e5+5;
using ll=long long;
int n;
ll x,sum;
set<ll>s;
int len;
struct node{
	ll l,r;
	bool operator <(const node P){
		return l<P.l;
	}
}p[N];
ll a[N];
inline ll gans(){
	if(len<=1)return 0;
	ll res=0;
	int curn=0;
	for(auto v:s)a[++curn]=v;
	ll pre=sum,suf=sum;
	curn=0;
	for(int i=len-1;i>=1;i--){
		pre-=a[i+1],suf-=a[len-i];
		if(pre==suf)continue;
		p[++curn]={pre,suf-1};
	}
	sort(p+1,p+curn+1);
	for(int i=1;i<curn;i++){
		if(p[i].r<p[i+1].l)res+=p[i].r-p[i].l+1;
		else{
			if(p[i+1].r<=p[i].r)p[i+1]=p[i];
			else{
				p[i+1].l=p[i].l;
			}
		}
	}
	res+=p[curn].r-p[curn].l+1;
	return res;
}
int main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(s.find(x)!=s.end()){
			s.erase(x);
			sum-=x;
			len--;
		}
		else{
			s.insert(x);
			sum+=x;
			len++;
		}
		if(1ll*n*len<=1e7){
			cout<<gans()<<"\n";
			continue;
		}
		if(len>10)cout<<max(sum-(*s.begin()*2),0ll)<<"\n";
		else cout<<gans()<<"\n";
	}
	return 0;
}

